/*
 * Ext JS Library 2.2
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */
Ext.apply(Ext.form.VTypes, {
    password : function(val, field) {
        if (field.initialPassField) {
            var pwd = Ext.getCmp(field.initialPassField);
            return (val == pwd.getValue());
        }
        return true;
    },

    passwordText : msg_error
});

Ext.onReady(function(){
		Ext.QuickTips.init();

    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'side';

	var regForm = new Ext.FormPanel({
        url:'register',
		renderTo: 'reg-form',
        frame:true,
        title: lbl_form_title,
        bodyStyle:'padding:5px 5px 0',
        labelAlign: 'right',        
        width: 350,
        waitMsgTarget: true,

        items: [{
			xtype: 'fieldset',
            id: 'fsLogin',
			title: lbl_form,
	        defaultType: 'textfield',
			width: 320,
			height: 230,
            defaults:{width:150},
			labelWidth: 120,
			items:[{
                fieldLabel: lbl_first_name,
                name: 'first_name',
                allowBlank:false
            },{
                fieldLabel: lbl_last_name,
                name: 'last_name',
                allowBlank:false
            },{
                fieldLabel: lbl_institution,
                name: 'institution',
                allowBlank:false
            }, {
                fieldLabel: lbl_email,
                name: 'email',
                vtype:'email',
                allowBlank:false
            }, {
                fieldLabel: lbl_password,
                inputType: 'password',
                name: 'password',
                id: 'pass',
                allowBlank:false
            },{
                fieldLabel: lbl_password_conf,                
                inputType: 'password',
                name: 'pass-cfrm',
        		vtype: 'password',
                allowBlank:false,
                initialPassField: 'pass' 
            }],
        	buttons: [{
            	text: btn_register,
            	type: 'submit',
				name: 'regsbmt',
				handler: function(){
					var form = regForm.getForm();
					if(form.isValid()){
						form.submit({url:'register', waitMsg: msg_register, success: regComplete});
					}
				}
        	}]
		},msgPanel = new Ext.Panel({
            id: 'msgPanel',
			region: 'center',
            hidden: true,			
			html: reg_msg
        })]
    	});
		var regComplete = function(form, action){
            /* uncomment if mail don't work
            var tempLink = 'Click <a href="' + action.result.msg + '">here</a> to active your acount!'; 
            */
			//Ext.Msg.alert(alert_status, alert_msg); //here add tempLink				            
            Ext.getCmp('fsLogin').hide();
            msgPanel.show();
		}

});